package com.github.xuemingyu.springboot.acticitycloud.controller.api;

import com.bidanet.bdcms.core.bean.ApiResult;
import com.bidanet.bdcms.core.vo.Page;
import com.github.xuemingyu.springboot.acticitycloud.entity.SakuraSign;
import com.github.xuemingyu.springboot.acticitycloud.service.SakuraSignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: xmy
 * \* Date: 2019/1/28
 * \* Time: 14:33
 * \
 */
@RestController
@RequestMapping("/sakuraSign")
public class SakuraSignApiController {
    @Autowired
    private SakuraSignService sakuraSignService;

    /**
     * 查看我的签到列表（樱花节）
     *
     * @param sakuraSign
     * @param page
     * @param request
     * @return
     */
    @RequestMapping("/queryByUserId")
    public ApiResult queryByUserId(SakuraSign sakuraSign, Page page, HttpServletRequest request, String startTime, String endTime) {
        sakuraSign.setUserId(request.getHeader("userId"));
        sakuraSignService.queryLike(sakuraSign, page, startTime, endTime);
        return ApiResult.success(page);
    }

    /**
     * 查看所有签到（樱花节）
     *
     * @param sakuraSign
     * @param page
     * @return
     */
    @RequestMapping("/queryAll")
    public ApiResult queryAll(SakuraSign sakuraSign, Page page, String startTime, String endTime) {
        sakuraSignService.queryLike(sakuraSign, page, startTime, endTime);
        return ApiResult.success(page);
    }

    @RequestMapping("/query")
    public ApiResult query(SakuraSign sakuraSign, Page page, String startTime, String endTime) {
        sakuraSignService.querAll(sakuraSign, page, startTime, endTime);
        return ApiResult.success(page);
    }

    @RequestMapping("/sign")
    public ApiResult sign(SakuraSign sakuraSign, HttpServletRequest request) {
        sakuraSign.setUserId(request.getHeader("userId"));
        try {
            sakuraSignService.insert(sakuraSign);
        } catch (Exception e) {
            return ApiResult.error(e.getMessage());
        }
        return ApiResult.success("签到成功");
    }

    /**
     * 审核签到
     *
     * @param ids
     * @return
     */
    @RequestMapping("/auditSignSuccess")
    public ApiResult auditSignSuccess(String ids) {
        try {
            sakuraSignService.auditSign(ids, 0L);
        } catch (Exception e) {
            return ApiResult.error(e.getMessage());
        }
        return ApiResult.success("审核成功");
    }

    /**
     * 拒绝签到
     *
     * @param ids
     * @return
     */
    @RequestMapping("/auditSignFailed")
    public ApiResult auditSignFailed(String ids) {
        try {
            sakuraSignService.auditSign(ids, 1L);
        } catch (Exception e) {
            return ApiResult.error(e.getMessage());
        }
        return ApiResult.success("已拒绝");
    }

    @RequestMapping("/delete")
    public ApiResult delete(Long id) {
        sakuraSignService.delete(id);
        return ApiResult.success("删除成功");
    }
}
